package pkg.tenproject.gest.HandFiles;


import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.Properties;



import pkg.tenproject.gest.mail.SendMail;

public class HandleFilesConnection {
	public static void main(String a)
	{
		HandleFilesConnection h = new HandleFilesConnection();
		h.writeDBFile("pippo", "login", "password","driver");
	}
	public boolean writeDBFile(String connectionString,String login,String password,String driver)
	{ 
		Properties props = new Properties();
		FileInputStream is = null;
		boolean esito;
		try {
			props = new Properties();
			File f1;
			  f1=new File("connection.properties");
			  
			  if(f1.exists()){
				  f1.delete();
			  }
			  f1.createNewFile();
			 is = new FileInputStream( f1 );
			props.load(is);
			if( connectionString != null )
				props.setProperty("connectionString", connectionString);
			if( login != null )
				props.setProperty(login, login);
			if( connectionString != null )
				props.setProperty("connectionString", connectionString);
			if( password != null )
				props.setProperty("password", password);
			if( driver != null )
				props.setProperty("driver", driver);
			esito = true;
			System.out.println(props.getProperty(connectionString));
		} catch (Exception e) {
			SendMail.sendMail("Errore nell'accesso del file di properties del DB", "ERRORE:\n"+e.getMessage());
			e.printStackTrace();
			esito = false;
		}
		finally
		{
			try {
				is.close();	
			} catch (Exception e2) {
				SendMail.sendMail("Errore nell'accesso del file di properties del DB", "ERRORE:\n"+e2.getMessage());
				e2.printStackTrace();
			}

		}
		return esito;
	}
}
